home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_1 / cpdist / keys.c < prev    next >
C/C++ Source or Header  |  1994-01-12  |  1KB  |  74 lines

  1. /*
  2.  *  KEYS.C
  3.  */
  4.  
  5. /*
  6.  * (c)Copyright 1992-93 by Tobias Ferber.
  7.  *
  8.  * This file is part of CPDIST.
  9.  *
  10.  * CPDIST is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published
  12.  * by the Free Software Foundation; either version 1 of the License,
  13.  * or (at your option) any later version.
  14.  *
  15.  * CPDIST is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with CPDIST; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include <ctype.h>
  26.  
  27. typedef struct lnode {
  28.   struct lnode *next;
  29.   char *key;
  30. } lnode;
  31.  
  32. static lnode *ln_head= (lnode *)0L;
  33.  
  34. ln_equals(char *s, char *t)
  35. {
  36.   while(*s && *t && toupper(*s)==toupper(*t))
  37.   { ++s;
  38.     ++t;
  39.   }
  40.  
  41.   return ((*s && *s!=':') || (*t && *t!=':')) ? 0:1;
  42. }
  43.  
  44. int ln_member(char *key)
  45. {
  46.   lnode *n;
  47.   for(n= ln_head; n && !ln_equals(n->key,key); n= n->next);
  48.   return n ? 1 : 0;
  49. }
  50.  
  51. int ln_addnode(char *key)
  52. {
  53.   lnode *n;
  54.  
  55.   if(n= (lnode *)malloc(sizeof(lnode)))
  56.   {
  57.     n->next= ln_head;
  58.     ln_head= n;
  59.     n->key = key;
  60.   }
  61.   return n ? 1:0;
  62. }
  63.  
  64. void ln_purge(void)
  65. {
  66.   lnode *n= ln_head;
  67.  
  68.   while(n)
  69.   { lnode *t= n;
  70.     n= n->next;
  71.     free(t);
  72.   }
  73. }
  74.